﻿using System.Runtime.InteropServices;
using System.Windows.Media;

namespace ImageProcessor.Shared.ImageExtensions
{

    [StructLayout(LayoutKind.Sequential)]
    public struct PixelColor
    {
        public byte Blue;
        public byte Green;
        public byte Red;
        public byte Alpha;

        public static PixelColor FromArgb(byte alpha, byte red, byte green, byte blue)
        {
            return
                new PixelColor
                {
                    Blue = blue,
                    Red = red,
                    Green = green,
                    Alpha = alpha
                };
        }

        public static PixelColor FromArgb(byte red, byte green, byte blue)
        {
            return
                new PixelColor
                {
                    Blue = blue,
                    Red = red,
                    Green = green,
                    Alpha = 255
                };
        }

        public int AsInt
        {
            get
            {
                return
                    Alpha << 24 // Alpha
                  | Red << 16  // R
                  | Green << 8   // G
                  | Blue << 0;   // B
            }
        }

        public static PixelColor FromColor(Color color)
        {
            return FromArgb(color.A, color.R, color.G, color.B);
        }
    }


}